import Vue from 'vue'
import Router from 'vue-router'

import Layout from '@/layout'

import dashboardRouter from './modules/dashboard'
import userRouter from './modules/user'
import homeinfoRouter from './modules/homeinfo'
import resumeRouter from './modules/resume'
import csRouter from './modules/cs'
import jobinfoRouter from './modules/jobinfo'
import tosRouter from './modules/tos'
import jobhelperRouter from './modules/jobhelper'
import coachingOrderRouter from './modules/coaching_order'
import orderRouter from './modules/order'
// import settingRouter from './modules/setting'

Vue.use(Router)
const originalPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

export const constantRoutes = [
  {
    path: '/',
    hidden: true,
    redirect: '/dashboard'
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: () => import('@/views/redirect/index')
    }]
  }, {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  }, {
    path: '/account',
    component: Layout,
    children: [{
      path: '/',
      component: () => import('@/views/account/index')
    }],
    hidden: true
  }, {
    path: '/notice',
    component: Layout,
    children: [{
      path: '/',
      component: () => import('@/views/notice/index')
    }, {
      path: 'me',
      component: () => import('@/views/notice/me')
    }, {
      path: 'info',
      component: () => import('@/views/notice/info')
    }],
    hidden: true
  }, {
    path: '/password',
    component: Layout,
    children: [{
      path: '/',
      component: () => import('@/views/account/password')
    }],
    hidden: true
  }, {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  }, {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  }, {
    path: '/403',
    component: () => import('@/views/error-page/403'),
    hidden: true
  }
]

export const asyncRoutes = [
  dashboardRouter,
  userRouter,
  homeinfoRouter,
  coachingOrderRouter,
  resumeRouter,
  jobinfoRouter,
  csRouter,
  jobhelperRouter,
  tosRouter,
  orderRouter,
  // settingRouter,
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history',
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
